package cn.itsource.order.mapper;


import cn.itsource.order.domain.OrderAdopt;
import org.apache.commons.lang3.time.DateUtils;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

public interface OrderAdoptMapper extends Mapper<OrderAdopt> {


    default OrderAdopt selectByOrderSn(String orderSn){

        //拼接条件
        Example example = new Example(OrderAdopt.class);
        example.and().andEqualTo("orderSn",orderSn);

        //返回数据
        return this.selectOneByExample(example);


    }

    default List<OrderAdopt> findOrders(){
        Date date = DateUtils.addMinutes(new Date(), -20);
        //查询20分钟之前到现在的订单 和状态的待支付state =0
        Example example = new Example(OrderAdopt.class);
        example.and().andBetween("lastConfirmTime",date,new Date())
                .andEqualTo("state",0);

        return this.selectByExample(example);
    }
}
